
#include "CBullet.h"

CBullet::CBullet(void)
{
	x = 0;
	y = 0;
}

CBullet::CBullet(double x1, double y1, double XMovement1, double YMovement1, CPlayer* player1, int id, Tiles* tiles1, int shots, bool seed1)
{
	if(seed1){
		char picfile[] = "res/seed.bmp";
		image = LoadImage(NULL, picfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	}
	else{
		char picfile[] = "res/bananaDead.bmp";
		image = LoadImage(NULL, picfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	}
	x = x1;
	y = y1;
	XMovement = XMovement1;
	player = player1;
	YMovement = YMovement1;
	ticks =0;
	tiles= tiles1;
	seed  = seed1;
}


CBullet::~CBullet(void)
{
}

bool CBullet::Update(){


	if(  ((player->x + 32 >= x && player->x + 32 <= x + 16) || (player->x >= x && player->x <= x + 16)) && ((player->y + 32 >= y && player->y <= y + 16) || (player->y >= y && player->y <= y + 16))){
		player->die();
		return false;
	}


	if(seed){
		if(tiles->canGoThere(x + XMovement, y + YMovement, 16,16)){
			x+= XMovement;
			y+= YMovement;
		ticks++;
			return true;
		}
		else{
			return false;
		}
	}
	else{

		if(YMovement > 0){
			YMovement += 0.06;
		}
		else{
			YMovement += 0.012;
		}
		if(tiles->canGoThere(x, y + YMovement, 16,64)){
			y += YMovement;
			ticks++;
		}
		else{
			if(YMovement < 0){
				YMovement = 0;
			}
			else{
				return false;
			}
		}
	}
	return true;
}
void CBullet::Draw(HDC graphics){
		if(seed){
			RenderHelper::RenderBitmap(graphics, image, x,y, 16, 16);
		}
		else{
			RenderHelper::RenderBitmap(graphics, image, x,y, 32, 64);
		}
}